package org.zw.android.framework.app;

import java.util.HashMap;
import java.util.Map;

import org.zw.android.framework.util.StringUtils;

/**
 * App Memory share
 * @author zhouwei
 *
 */
public final class AppMemoryShared {

	private static Map<String, Object> ValuesMap = new HashMap<String, Object>();
	
	private AppMemoryShared(){
		
	}
	
	public static void clear(){
		ValuesMap.clear() ;
	}
	
	public static void putObject(String key, Object value){
		
		if(check(key)){
			ValuesMap.put(key, value);
		}
	}
	
	public static void remove(String key){
		
		if(check(key)){
			ValuesMap.remove(key);
		}
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T findObject(String key){
		
		try{
			if(check(key)){
				return (T)ValuesMap.get(key);
			}
		} catch(Exception e){
			e.printStackTrace() ;
		}
		
		return null ;
	}
	
	private static boolean check(String key){
		return !StringUtils.isEmpty(key);
	}
}
